package com.vito.dcs.water.waterGradation.action;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.authoriza.cache.SessionMap;
import com.vito.base.authoriza.model.UserModel;
import com.vito.base.exception.ParamErrorException;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.base.util.Validata;
import com.vito.dcs.water.waterGradation.model.WaterGradationModel;
import com.vito.dcs.water.waterGradation.service.WaterGradationService;

/**
 * 水稳站筛孔合成级配统计
 * @author lyhao
 *
 */
@Controller
@RequestMapping("/dcs/water/waterGradation")
public final class WaterGradationAction extends BaseAction {
	
	private static final Logger log = LoggerFactory.getLogger(WaterGradationAction.class);
	
	@Reference
	private WaterGradationService waterGradationService;
	
	/**
	 * 保存
	 * @param waterGradationModel
	 * @return
	 */
	@RequestMapping("saveWaterGradation")
	@ResponseBody
	public Result saveWaterGradation(@RequestBody WaterGradationModel waterGradationModel){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			Validata.isNullOrEmpty(waterGradationModel, "水稳站筛孔合成级配统计不能为空");
			waterGradationService.saveWaterGradation(waterGradationModel);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.SAVESUC);
		}catch(Exception ex){
			log.error("保存失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 分页查询
	 * @param waterGradationModel
	 * @return
	 */
	@RequestMapping("queryAllWaterGradationByPage")
	@ResponseBody
	public Result queryAllWaterGradationByPage(WaterGradationModel waterGradationModel){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			Validata.isNullOrEmpty(waterGradationModel, "水稳站筛孔合成级配统计不能为空");
			res.setData(waterGradationService.queryAllByPage(waterGradationModel));
			res.setCode(Result.CODE_OK);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 查询
	 * @param waterGradationModel
	 * @return
	 */
	@RequestMapping("queryWaterGradation")
	@ResponseBody
	public Result queryWaterGradation(WaterGradationModel waterGradationModel){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			res.setData(waterGradationService.query(waterGradationModel));
			res.setCode(Result.CODE_OK);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
		
	/**
	 * 修改
	 * @param waterGradationModel
	 * @return
	 */
	@RequestMapping("updateWaterGradation")
	@ResponseBody
	public Result updateWaterGradation(@RequestBody WaterGradationModel waterGradationModel){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			Validata.isNullOrEmpty(waterGradationModel.getId(),"主键不能为空");
			res.setData(waterGradationService.update(waterGradationModel));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.UPDSUC);
			
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("更新失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 删除
	 * @param waterGradationModel
	 * @return
	 */
	@RequestMapping("deleteWaterGradation")
	@ResponseBody
	public Result deleteWaterGradation(WaterGradationModel waterGradationModel){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			Validata.isNullOrEmpty(waterGradationModel.getCheckeds(), "所选项不能为空");
			res.setData(waterGradationService.delete(waterGradationModel));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.DELCOM);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("删除失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 查询曲线图数据
	 * @param map
	 * @return
	 */
	@RequestMapping("queryChartData")
	@ResponseBody
	public Result queryChartData(@RequestParam Map<String,String> map){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			res.setCode(Result.CODE_OK);
			res.setData(waterGradationService.queryChartData(map));
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
}
